/**
 * Created by abdulazizalonizi on 8/7/17.
 */
import java.util.Scanner ;
public class Task1 {
    public static void main (String [] args)
    {
        System.out.println("This program computes the approximate value of the factorial using the formula proposed by R. W. Gosper.\n" +
                "To use this program, the input should be nonegative. Also use values not greater than 13\n");

        System.out.println("Enter a positive integer n not greater than 13: ");
        Scanner kb = new Scanner (System.in);
        int n = kb.nextInt();
        factorial(n);








    }

    public static void factorial (int n )
    {
       // System.out.println("This program computes the approximate value of the factorial using the formula proposed by R. W. Gosper.\n" +
               // "To use this program, the input should be nonegative. Also use values not greater than 13");

         if(n<0 | n>13)
             throw new IllegalArgumentException("Error : Wrong input");
         else
         {
             double result = Math.pow(n,n)*Math.pow(Math.E,-n)*Math.sqrt(((2*n)+1/3.0)*Math.PI);
             System.out.println("The approximate factorial of "+n +" is "+result);
         }


    }
}







//QWJkdWxheml6IEFsb25pemkgQ3JlYXRlZCB0aGlzIGNvZGUgLCBoZSB3b3JrZWQgdmVyeSBoYXJkIG9uIGl0ICwgRE8gTk9UIFVTRSBJVCBUTyBTVUJNSVQgWU9VUiBBU1NJR05NRU5UIA0K
//UTF_8